package com.wu.base;


import com.wu.exception.EnumInterface;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(description = "通用响应返回对象")
public class ApiResponse<T> {

    @ApiModelProperty(value = "结果代码", position = 0)
    private String code;

    @ApiModelProperty(value = "错误信息", position = 1)
    private String msg;

    @ApiModelProperty(value = "结果数据", position = 2 )
    private T data;

    public ApiResponse() {

    }

    public ApiResponse(EnumInterface excCode) {
        this.code = excCode.getCode().toString();
        this.msg = excCode.getDesc().toString();
    }

    public void setApiResponse(EnumInterface excCode) {
        this.code = excCode.getCode().toString();
        this.msg = excCode.getDesc().toString();
    }

    /**
     * 设置相应数据
     *
     * @param data
     */
    public void setResponseData(T data) {
        if (data != null) {
            this.setData(data);
        } else {
            ApiResponse apiResponse = new ApiResponse();
            apiResponse.setData(data);
        }
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

}
